package com.bkgy.modular.tbrealtimevariable.controller;

import com.alibaba.fastjson.JSON;
import com.bkgy.modular.tbrealtimevariable.entity.JTbRealTimeVariable;
import com.bkgy.modular.tbrealtimevariable.service.TbRealTimeVariableService;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 仿真数据
 *
 * @author 生成器生成
 * @date 2022-10-17 09:29:12
 */
@RestController
@RequestMapping("/tbRealTimeVariable")
public class TbRealTimeVariableController {

    @Resource
    private TbRealTimeVariableService tbRealTimeVariableService;

    /**
     * 添加记录
     *
     * @param data userId 用户id
     * @param data sname 用户姓名
     */
    @CrossOrigin
    @RequestMapping(value = {"/insert"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData insertDataTbRealTimeVariable(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tbRealTimeVariableService.insertDataTbRealTimeVariable(data, userId, CodiUtil.returnLm(sname));
    }

    /**
     * 根据主键删除对象
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteOne"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataTbRealTimeVariableOne(@RequestBody String data) {
        try {
            JTbRealTimeVariable jTbRealTimeVariable = JSON.parseObject(data, JTbRealTimeVariable.class);
            return tbRealTimeVariableService.deleteOne(jTbRealTimeVariable.getIndocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键字符串删除多个对象
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteMany"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataTbRealTimeVariableMany(@RequestBody String data) {
        try {
            JTbRealTimeVariable jTbRealTimeVariable = JSON.parseObject(data, JTbRealTimeVariable.class);
            return tbRealTimeVariableService.deleteMany(jTbRealTimeVariable.getStr_indocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 修改记录
     *
     * @param data       json字符串
     * @param loginToken 请求头参数字符串对象
     */
    @CrossOrigin
    @RequestMapping(value = {"/update"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData updateDataTbRealTimeVariable(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tbRealTimeVariableService.updateDataTbRealTimeVariable(data, userId, CodiUtil.returnLm(sname));
    }

    /**
     * 分页查看记录
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByPage"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataTbRealTimeVariableByPage(@RequestBody String data) {
        return tbRealTimeVariableService.findDataTbRealTimeVariableByPage(data);
    }

    /**
     * 根据主键查询单条记录
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByIndocno"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataTbRealTimeVariableByIndocno(@RequestBody String data) {
        return tbRealTimeVariableService.findDataTbRealTimeVariableByIndocno(data);
    }
}